﻿#region ... Copyright Notice ...
/*
   Copyright 2008 Tyler Jensen

	Author: Tyler Jensen    http://www.tsjensen.com/blog

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
#endregion

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Atrax.Security;

namespace A2KeyMan
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void btnGen_Click(object sender, EventArgs e)
		{
			long id = 0;
			if (long.TryParse(txtKeyNum.Text, out id))
			{
				KeyManager km = new KeyManager();
				string key = km.CreateLicenseKey(id);
				txtGeneratedKey.Text = key;
			}
			else
				MessageBox.Show("Key id number must be an integer.");
		}

		private void btnExtract_Click(object sender, EventArgs e)
		{
			string key = txtGenKeyToExtract.Text;
			KeyManager km = new KeyManager();
			if (km.IsValidLicenseKey(key))
			{
				long id = km.GetLicenseKeyId(key);
				txtExtractedKeyNum.Text = id.ToString();
			}
			else
				MessageBox.Show("Invalid key.");
		}

		private void btnClear_Click(object sender, EventArgs e)
		{
			this.txtExtractedKeyNum.Text = string.Empty;
			this.txtGeneratedKey.Text = string.Empty;
			this.txtGenKeyToExtract.Text = string.Empty;
			this.txtKeyNum.Text = string.Empty;
		}
	}
}
